<template>
    <div class="content-main">
        <div class="breadcrumb">
            <div class="breadcrumb-icon">
                <img src="./../../assets/images/breadcrumb_icon.png" />
            </div>
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>实训报告评价</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="content-box">
            <div class="search-box">
                <div class="search-item">
                    <span class="search-title">班级: </span>
                    <el-select
                        v-model="classValue"
                        placeholder="请选择班级"
                        value-key="value"
                        style="float:left;">
                        <el-option
                        v-for="item in classStatus"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                        </el-option>
                    </el-select>
                </div>
                <!-- <div class="search-item">
                    <span class="search-title">案例状态: </span>
                    <el-select
                        v-model="projectValue"
                        placeholder="请选择案例状态"
                        value-key="value"
                        style="float:left;">
                        <el-option
                        v-for="item in projectStatus"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                        </el-option>
                    </el-select>
                </div> -->
                <div class="search-item">
                    <span class="search-title">学生信息: </span>
                    <el-input v-model="info" placeholder="请输入学生信息" style="float:left; width:auto;"></el-input>
                </div>
                <div class="search-item">
                    <el-button type="primary" @click="searchFn">搜索</el-button>
                </div>
            </div>
            <div class="table-content" v-loading="tableLoading">
                <el-table
                :data="tableData"
                border
                style="width: 100%">
                    <el-table-column prop="userName" label="学生姓名">
                    </el-table-column>
                    <el-table-column prop="userNumber" label="学号">
                    </el-table-column>
                    <el-table-column prop="className" label="班级">
                    </el-table-column>
                    <el-table-column prop="name" label="报告名称">
                    </el-table-column>
                    <!-- <el-table-column label="案例状态">
                        <template slot-scope="scope">
                            {{ scope.row.endMark == 0 ? '未结项' : '已结项' }}
                        </template>
                    </el-table-column> -->
                    <el-table-column label="报告成绩">
                        <template slot-scope="scope">
                            <span v-if="scope.row.reportLevel == 1">差</span>
                            <span v-else-if="scope.row.reportLevel == 2">中</span>
                            <span v-else-if="scope.row.reportLevel == 3">良</span>
                            <span v-else-if="scope.row.reportLevel == 4">优</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="操作">
                        <template slot-scope="scope">
                            <el-button type="text" size="small" @click="lookFn(scope.row.reportId,scope.row.userId)">查看</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="currentPage"
                    :page-size="pagesize"
                    layout="total, prev, pager, next, jumper"
                    :total="totalCount"
                    style="margin-top: 20px; text-align: center;">
                </el-pagination>
            </div>
        </div>
    </div>
</template>

<script>
    import BreadCrumbBack from '@/components/breadCrumbBack.vue'
    export default {
        components: {
            BreadCrumbBack
        },
        data () {
            //手机号验证
            var validPhone = (rule, value,callback)=>{
                if (!value){
                    callback(new Error('请输入电话号码'))
                }else  if (!isvalidPhone(value)){
                    callback(new Error('请输入正确的11位手机号码'))
                }else {
                    callback()
                }
            }
            return {
                // projectStatus: [
                //      {
                //         value: '',
                //         label: '全部'
                //     },
                //     {
                //         value: 1,
                //         label: '已结项'
                //     },
                //     {
                //         value: 0,
                //         label: '未结项'
                //     }
                // ],
                // projectValue: '',
                classStatus: [
                    {
                        label: '全部',
                        value: ''
                    }
                ],
                classValue: '',
                info: '',
                tableLoading: false,
                tableData: [],
                currentPage:1,
                pagesize:10,
                totalCount: 1000,
            }
        },
        created () {
            this.init()     //初始化
            this.initTable()     //初始化
        },
        methods: {
            init() {
                let self = this
                self.$http.get('/dataplatform/common/search/listClassItem').then((response) => {
                    let res = response.data
                    if(res.code == '200') {
                        for(let i = 0; i < res.data.classList.length; i++){
                            let classJson = {}
                            classJson.value = res.data.classList[i].id
                            classJson.label = res.data.classList[i].name
                            self.classStatus.push(classJson)
                        }
                    }else if(res.code == '401'){
                        self.$router.replace({
                            path:'/login'
                        })
                    }else{
                        self.$message.error(res.message)
                    }
                })
            },
            initTable(){
                let self = this
                self.$http.get('/dataplatform/basis/functions/report/t/teacherEnvironmentReportList?pageNum='+self.currentPage+'&pagesize='+self.pagesize+'&classId='+self.classValue+'&userName='+self.info).then((response) => {
                    let res = response.data
                    if(res.code == '200') {
                        self.tableData = res.data.list
                        self.totalCount = res.data.total
                    }else if(res.code == '401'){
                        self.$router.replace({
                            path:'/login'
                        })
                    }else{
                        self.$message.error(res.message)
                    }
                })
            },
            //表格分页
			handleSizeChange: function (size) {
				this.pagesize = size;
			},
			handleCurrentChange: function(currentPage) {
                this.currentPage = currentPage
                this.initTable()
            },
            //搜索
            searchFn() {
                this.currentPage = 1
                this.initTable()
            },
            lookFn(reportId, userId){
                this.$router.push({
                    path: '/teacher/trainingReportDetail',
                    query: {
                        projectId: reportId,
                        userId: userId
                    }
                })
            }
        }
    }
</script>
